﻿var hover = false;
(function ($j) {

    $j.fn.spasticNav = function (options) {

        options = $j.extend({
            overlap: 500,
            speed: 500,
            reset: 500,
            color: '#fff',
            easing: 'easeOutBack'
        }, options);

        return this.each(function () {

            var nav = $j(this),
		 		currentPageItem = $j('#selected', nav),
		 		blob,
		 		reset;

            $j('<li id="blob"></li>').css({
                width: currentPageItem.outerWidth(),
                height: 30,
                left: currentPageItem.position().left,
                //top: $j('#ulSubTopMenu').position().top + $j(".logo").position().top + 15,
                top: 5,
                backgroundColor: options.color
            }).appendTo(this);

            blob = $j('#blob', nav);
            var focusTab = null;
            $j('li:not(#blob)', nav).hover(function () {
                clearTimeout(reset);
                focusTab = $j(this);
                focusTab.find('span').css({
                    'color': '#e20000',
                    'textShadow': 'none'
                });
                blob.animate(
{
    left: $j(this).position().left,
    width: $j(this).width()
},
{
    duration: options.speed,
    easing: options.easing,
    queue: false,
    complete: function () { }
}
);
                $j("#ulSubTopMenu").find('li a span').css({
                    'color': "#e20000",
                    'textShadow': "none"
                });
                focusTab.find('span').css({
                    'color': '#0095DA',
                    'textShadow': "0px 1px 2px #C1C0C0"
                });
            }, function () {
                // mouse out
                reset = setTimeout(function () {
                    focusTab.find('span').css({
                        'color': '#e20000',
                        'textShadow': 'none'
                    });
                    $j('#selected').find('span').animate({
                        color: "#0095DA",
                        textShadow: "0px 1px 2px #C1C0C0"
                    }, { duration: 1 });
                    blob.animate({
                        width: currentPageItem.outerWidth(),
                        left: currentPageItem.position().left
                    }, 400, options.easing, function () {
                    })
                }, options.reset, function () {
                    currentPageItem.find('span').css({
                        color: "#0095DA",
                        textShadow: "0px 1px 2px #C1C0C0"
                    });
                });
            });
        }); // end each 
    };

})(jQuery);